package com.fzrskj.cloud.free.miniservice.utils;

import ms.core.object.CObject;

import java.util.Map;

/**
 * PriceUtils.
 *
 * @author zj.
 *         Created on 2019/5/29 0029.
 */
public class DiyProductPriceUtils extends CObject {
    /**
     * 获取价格.
     * @param serverCode 服务编码.
     * @param params 参数.
     * @return 价格.
     */
    public Double getPrice (String serverCode, Map<String, Object> params) {
        MiniServiceRequest miniServiceRequest = new MiniServiceRequest();
        Map result = miniServiceRequest.post(serverCode, "/api/price/new", params, Map.class);
        if (null == result) {
            this.setErrCode(miniServiceRequest.getErrCode(), miniServiceRequest.getMsg());
            return null;
        }
        return Double.valueOf(result.get("price").toString());
    }

    /**
     * 获取续费价格.
     * @param serverCode 服务编码.
     * @param params 参数.
     * @return 价格.
     */
    public Double getRenewPrice (String serverCode, Map<String, Object> params) {
        MiniServiceRequest miniServiceRequest = new MiniServiceRequest();
        Map result = miniServiceRequest.post(serverCode, "/api/price/renew", params, Map.class);
        if (null == result) {
            this.setErrCode(miniServiceRequest.getErrCode(), miniServiceRequest.getMsg());
            return null;
        }
        return Double.valueOf(result.get("price").toString());
    }
}
